# -*- coding: utf-8 -*-
# @Time : 2025/10/27 11:07:55
# @Desc : 创建app 使用waitress跨平台服务器
# @Author : Sean
# @File   : ctreate_app.py

from bottle import Bottle, run
from api.index import index_app
from api.other import other_app
from config.config import Config
import threading


root = Bottle()
root.mount("/", index_app)  # mount index接口
root.mount("/api/other", other_app)  # mount other接口


def start_server(port):
    """启动Web服务器"""
    run(
        root,
        host="127.0.0.1",
        port=port,
        quiet=not Config.log,
        debug=Config.debug,
        server="waitress",
    )


def start_server_thread(port):
    """在后台线程中启动Web服务器"""
    server_thread = threading.Thread(target=start_server, args=(port,), daemon=True)
    server_thread.start()
